-- drop function if exists sm_sc.fv_d_mx_ele_2d_2_3d_dloss_dindepdt(anyarray, int);
create or replace function sm_sc.fv_d_mx_ele_2d_2_3d_dloss_dindepdt
(
  i_dloss_ddepdt_3d      anyarray      ,
  -- i_cnt_per_grp         int           ,       -- 升维的新增维度的维度长度(元素个数)。如果 i_dim_pin_ele = 1 则，新增维度为3；如果 i_dim_pin_ele = 2 则，新增维度为2。
  i_dim_pin_ele          int               -- 自变量被定住的维度，1 或 2
)
returns anyarray
as
$$
-- declare

begin
  if array_ndims(i_dloss_ddepdt_3d) <> 3
  then 
    raise exception 'ndims should be 3.';
  end if;

  if i_dim_pin_ele = 1
  then 
    return 
      sm_sc.fv_mx_ele_3d_2_2d(i_dloss_ddepdt_3d, array[2, 3], 3)
    ;
  elsif i_dim_pin_ele = 2
  then 
    return 
      sm_sc.fv_mx_ele_3d_2_2d(i_dloss_ddepdt_3d, array[1, 2], 2)
    ;
  end if;
end
$$
language plpgsql stable
parallel safe
cost 100;
-- -- set search_path to sm_sc;
-- select sm_sc.fv_d_mx_ele_2d_2_3d_dloss_dindepdt
--   (
--     sm_sc.fv_mx_ele_2d_2_3d(array[[1,2,3,4,5,6,7,8,9,10,11,12],[21,22,23,24,25,26,27,28,29,30,31,32]], 3, 1)
--     , 1
--   );
-- select sm_sc.fv_d_mx_ele_2d_2_3d_dloss_dindepdt
--   (
--     sm_sc.fv_mx_ele_2d_2_3d(array[[1,2],[3,4],[5,6],[7,8],[9,10],[11,12],[21,22],[23,24],[25,26],[27,28],[29,30],[31,32]], 3, 2)
--     , 2
--   );